package com.example.administrator.szb.activity;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.bumptech.glide.Glide;
import com.example.administrator.szb.R;
import com.example.administrator.szb.adapter.BaseAdapter;
import com.example.administrator.szb.activity.base.BaseActivity;
import com.example.administrator.szb.bean.DDXQBean;
import com.example.administrator.szb.bean.IndexBean;
import com.example.administrator.szb.bean.MyXMBean;
import com.example.administrator.szb.bean.ResultBean;
import com.example.administrator.szb.config.FragmentsFlag;
import com.example.administrator.szb.tinkerutil.SampleApplicationLike;
import com.example.administrator.szb.http.HttpUtil;
import com.example.administrator.szb.http.URLAddress;
import com.example.administrator.szb.util.DialogUtil;
import com.example.administrator.szb.util.GetJsonDataUtil;
import com.example.administrator.szb.util.ScreenExpressionUtils;
import com.example.administrator.szb.util.Toasts;
import com.example.administrator.szb.xzyw.SuccessActivity;
import com.iarcuschin.simpleratingbar.SimpleRatingBar;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * Created by D N on 2017/10/27.
 */

public class XMXQActivity_my extends BaseActivity {
    @Bind(R.id.xmxq_my_recyclerview)
    RecyclerView xmxqMyRecyclerview;

    IndexBean indexBean;

    View headview_xnztm, headview_jg;
    int statu;//订单状态

    int dd_id;//订单id
    int genre;//1,我申请，2，申请我的

    String info_dd = "";//订单信息 toolbar上显示
    @Bind(R.id.xmxq_my_button_jjjd)
    Button xmxqMyButtonJjjd;
    @Bind(R.id.xmxq_my_button_ljjd)
    Button xmxqMyButtonLjjd;
    @Bind(R.id.xmxq_my_ll)
    LinearLayout xmxqMyLl;

    public static DDXQBean ddxqBean;
    BaseAdapter<MyXMBean.DataBean.ABean.ServiceCounBean> adapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.xmxq_my_activity);
        ButterKnife.bind(this);
        headview_jg = LayoutInflater.from(XMXQActivity_my.this).inflate(R.layout.xmxq_my_headview, null);
        SampleApplicationLike.getActivitiesInstance().add(this);
        hasIntent();


        initToolbarThree(R.id.xmxq_my_toolber_include, "项目详情", info_dd, new Callback() {
            @Override
            public void doSomeThing() {
                //Toasts.show(XMXQActivity_my.this, "do something", Toast.LENGTH_SHORT);
                if (statu == 0) {
                    Intent intent = new Intent(XMXQActivity_my.this, YJFKActivity.class);
                    intent.putExtra("who", FragmentsFlag.Activity_XMXQ.ordinal());
                    /**
                     * todo id_dd为订单号
                     */
                    intent.putExtra("id_dd", 0);
                    startActivity(intent);
                } else if (statu == 1) {
                    Intent intent = new Intent(XMXQActivity_my.this, XZJGActivity.class);
                    intent.putExtra("id_dd", 0);
                    startActivity(intent);
                }
            }
        });

        requestXMXQ();
    }

    private void hasIntent() {
        dd_id = getIntent().getIntExtra("dd_id", -1);
        genre = getIntent().getIntExtra("genre",-1);
        //changeYM();//根据订单状态显示页面
    }

    private void changeYM() {
        if (statu == 0) {
            info_dd = "取消订单";
            headview_jg.findViewById(R.id.linearLayout).setVisibility(View.GONE);
        } else if (statu == 1) {
            info_dd = "选择机构";
        }
    }

    private void requestXMXQ() {
        HashMap<String,String> map = new HashMap<>();
        map.put("code", HttpUtil.getParam()+"");
        map.put("indent_id",dd_id+"");
        map.put("users_id",SampleApplicationLike.getUserloginInstance().getId()+"");
        map.put("genre",genre+"");

        String json = GetJsonDataUtil.simpleMapToJsonStr(map);
        String url =  URLAddress.URLBASE + URLAddress.URL_DDXQ;
        HttpUtil.RequestGsonPost(SampleApplicationLike.getQueueInstance(), Request.Method.POST, DDXQBean.class, URLAddress.URLBASE + URLAddress.URL_DDXQ, map, new Response.Listener() {
            @Override
            public void onResponse(Object response) {
                ddxqBean = (DDXQBean) response;
                if (ddxqBean.getResult() == 1){
                    initView();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });


    }

    private void initView() {
        initRecyclerview();
    }

    private void initRecyclerview() {
        xmxqMyRecyclerview.setLayoutManager(new LinearLayoutManager(this));
        HashMap<Integer, MyXMBean.YWInfoData> map = (HashMap<Integer, MyXMBean.YWInfoData>) ddxqBean.getData().getIndentInfo();
        List listKey = new ArrayList<>();
         final List listValue = new ArrayList<MyXMBean.YWInfoData>();
        Iterator it = map.keySet().iterator();
        while (it.hasNext()) {
            String key = it.next().toString();
            listKey.add(key);
            listValue.add(map.get(Integer.parseInt(key)));
        }
        MyXMBean.YWInfoData lxr = new MyXMBean.YWInfoData();
        lxr.setKeyName("联系人");
        lxr.setValueName(ddxqBean.getData().getName());



        MyXMBean.YWInfoData lxfs = new MyXMBean.YWInfoData();
        lxfs.setKeyName("联系方式");
        lxfs.setValueName(ddxqBean.getData().getTel());

        MyXMBean.YWInfoData qtyq = new MyXMBean.YWInfoData();
        qtyq.setKeyName("其他要求");
        qtyq.setValueName(ddxqBean.getData().getContent());

        listValue.add(lxr);
        listValue.add(lxfs);
        listValue.add(qtyq);


        BaseAdapter<MyXMBean.YWInfoData> adapter = new BaseAdapter<MyXMBean.YWInfoData>(this, listValue) {
            @Override
            public void convert(int position, BaseViewHolder holder, MyXMBean.YWInfoData bean) {




                if (position == listValue.size()-2){
                    ((TextView)holder.getView(R.id.view_xmxq_text_two_keyname)).setText(bean.getKeyName());
                    ((TextView)holder.getView(R.id.view_xmxq_text_two_valuename)).setText(bean.getValueName());

                }else if (position > listValue.size() - 2) {
                    ((TextView)holder.getView(R.id.view_xmxq_text_three_keyname)).setText(bean.getKeyName());
                    ((TextView)holder.getView(R.id.view_xmxq_text_three_valuename)).setText(bean.getValueName());
                }else {
                    ((TextView)holder.getView(R.id.view_xmxq_text_keyname)).setText(bean.getKeyName());
                    ((TextView)holder.getView(R.id.view_xmxq_text_valuename)).setText(bean.getValueName());
                }
            }

            @Override
            public int getLayoutId(int viewType) {
                if (viewType == listValue.size() - 2) {
                    return R.layout.view_xmxq_item_two;
                } else if (viewType > listValue.size() - 2) {

                    if (genre == 2 && viewType == listValue.size() - 1){
                        return R.layout.view_xmxq_item_empty;
                    }

                    return R.layout.view_xmxq_item_three;
                }
                return R.layout.view_xmxq_item;
            }
        };

        try{
            handlerHeadView_jg();
        }catch (Exception e){
            headview_jg.findViewById(R.id.constraintLayout2).setVisibility(View.GONE);
            headview_jg.findViewById(R.id.linearLayout).setVisibility(View.GONE);

            Toasts.show(this, "项目状态丢失", Toast.LENGTH_SHORT);
        }

        adapter.addHeaderView(headview_jg);
        xmxqMyRecyclerview.setAdapter(adapter);
    }

    private void handlerHeadView_jg() {
        if (genre == 2 && ddxqBean.getData().getServiceCoun() != null){
            ddxqBean.getData().getServiceCoun().clear();
            headview_jg.findViewById(R.id.constraintLayout2).setVisibility(View.GONE);
        }
        ((TextView)headview_jg.findViewById(R.id.textView_ywlx_statu)).setText(ddxqBean.getData().getBusinessName());

        if ((double)ddxqBean.getData().getStatusType() == 1&& genre == 1){

            if (ddxqBean.getData().getServiceCoun() !=null){
                headview_jg.findViewById(R.id.constraintLayout2).setVisibility(View.VISIBLE);
            }else{
                headview_jg.findViewById(R.id.constraintLayout2).setVisibility(View.GONE);
            }
            //headview_jg.findViewById(R.id.constraintLayout2).setVisibility(View.GONE);
            headview_jg.findViewById(R.id.linearLayout).setVisibility(View.GONE);
            ((TextView) headview_jg.findViewById(R.id.textView135)).setText("项目状态："+ddxqBean.getData().getStatus().toString());
            initToolbarThree(R.id.xmxq_my_toolber_include, "项目详情", "取消订单", new Callback() {
                @Override
                public void doSomeThing() {
                    Toasts.show(XMXQActivity_my.this, "do something", Toast.LENGTH_SHORT);
                    if ((double)ddxqBean.getData().getStatusType() == 1) {
                        Intent intent = new Intent(XMXQActivity_my.this, YJFKActivity.class);
                        intent.putExtra("who", FragmentsFlag.Activity_XMXQ.ordinal());
                        /**
                         * todo id_dd为订单号
                         */
                        intent.putExtra("id_dd", ddxqBean.getData().getId());
                        startActivity(intent);
                    } else if ((double)ddxqBean.getData().getStatusType() == 6) {
                        Intent intent = new Intent(XMXQActivity_my.this, XZJGActivity.class);
                        intent.putExtra("id_dd", 0);
                        startActivity(intent);
                    }
                }
            });
        }

        /**
         * 订单取消，（帮我找机构）
         */
       else if ((double)ddxqBean.getData().getStatusType() == 10 && ddxqBean.getData().getServiceCoun() == null && genre == 1){
            headview_jg.findViewById(R.id.constraintLayout2).setVisibility(View.GONE);
            headview_jg.findViewById(R.id.linearLayout).setVisibility(View.VISIBLE);
            ((TextView) headview_jg.findViewById(R.id.textView135)).setText("项目状态："+ddxqBean.getData().getStatus().toString());
            ((TextView)headview_jg.findViewById(R.id.xmxq_headview_ddyy_content)).setText((String)ddxqBean.getData().getReasons());
            initToolbarThree(R.id.xmxq_my_toolber_include, "项目详情", "", new Callback() {
                @Override
                public void doSomeThing() {
                    Toasts.show(XMXQActivity_my.this, "do something", Toast.LENGTH_SHORT);
                    if ((double)ddxqBean.getData().getStatusType() == 1) {
                        Intent intent = new Intent(XMXQActivity_my.this, YJFKActivity.class);
                        intent.putExtra("who", FragmentsFlag.Activity_XMXQ.ordinal());
                        /**
                         * todo id_dd为订单号
                         */
                        intent.putExtra("id_dd", ddxqBean.getData().getId());
                        startActivity(intent);
                    } else if ((double)ddxqBean.getData().getStatusType() == 6) {
                        Intent intent = new Intent(XMXQActivity_my.this, XZJGActivity.class);
                        intent.putExtra("id_dd", 0);
                        startActivity(intent);
                    }
                }
            });
        }
        /**
         * 订单取消(自己找机构);
         */
        else if ((double)ddxqBean.getData().getStatusType() == 10 && ddxqBean.getData().getServiceCoun() != null && genre == 1){
            headview_jg.findViewById(R.id.constraintLayout2).setVisibility(View.VISIBLE);
            headview_jg.findViewById(R.id.linearLayout).setVisibility(View.VISIBLE);
            ((TextView) headview_jg.findViewById(R.id.textView135)).setText("项目状态："+ddxqBean.getData().getStatus().toString());
            ((TextView)headview_jg.findViewById(R.id.xmxq_headview_ddyy_content)).setText((String)ddxqBean.getData().getReasons());
            initToolbarThree(R.id.xmxq_my_toolber_include, "项目详情", "", new Callback() {
                @Override
                public void doSomeThing() {
                    Toasts.show(XMXQActivity_my.this, "do something", Toast.LENGTH_SHORT);
                    if ((double)ddxqBean.getData().getStatusType() == 1) {
                        Intent intent = new Intent(XMXQActivity_my.this, YJFKActivity.class);
                        intent.putExtra("who", FragmentsFlag.Activity_XMXQ.ordinal());
                        /**
                         * todo id_dd为订单号
                         */
                        intent.putExtra("id_dd", ddxqBean.getData().getId());
                        startActivity(intent);
                    } else if ((double)ddxqBean.getData().getStatusType() == 6) {
                        Intent intent = new Intent(XMXQActivity_my.this, XZJGActivity.class);
                        intent.putExtra("id_dd", 0);
                        startActivity(intent);
                    }
                }
            });
        }


       else if ((double)ddxqBean.getData().getStatusType() == 1&& genre == 2){
            xmxqMyLl.setVisibility(View.VISIBLE);
            if (ddxqBean.getData().getServiceCoun() !=null){
                headview_jg.findViewById(R.id.constraintLayout2).setVisibility(View.GONE);
            }else{
                headview_jg.findViewById(R.id.constraintLayout2).setVisibility(View.GONE);
            }
            headview_jg.findViewById(R.id.linearLayout).setVisibility(View.GONE);
            ((TextView) headview_jg.findViewById(R.id.textView135)).setText("项目状态："+ddxqBean.getData().getStatus().toString());
            initToolbarThree(R.id.xmxq_my_toolber_include, "项目详情", "", new Callback() {
                @Override
                public void doSomeThing() {
                    Toasts.show(XMXQActivity_my.this, "do something", Toast.LENGTH_SHORT);
                    if ((double)ddxqBean.getData().getStatusType() == 1) {
                        Intent intent = new Intent(XMXQActivity_my.this, YJFKActivity.class);
                        intent.putExtra("who", FragmentsFlag.Activity_XMXQ.ordinal());
                        /**
                         * todo id_dd为订单号
                         */
                        intent.putExtra("id_dd", 0);
                        startActivity(intent);
                    } else if ((double)ddxqBean.getData().getStatusType() == 6) {
                        Intent intent = new Intent(XMXQActivity_my.this, XZJGActivity.class);
                        intent.putExtra("id_dd", 0);
                        startActivity(intent);
                    }
                }
            });
        }

        else if((double)ddxqBean.getData().getStatusType() == 7&& genre == 1 ){
            headview_jg.findViewById(R.id.linearLayout).setVisibility(View.GONE);
            initToolbarThree(R.id.xmxq_my_toolber_include, "项目详情", "", new Callback() {
                @Override
                public void doSomeThing() {
                }
            });
            if (ddxqBean.getData().getServiceCoun() !=null){
                headview_jg.findViewById(R.id.constraintLayout2).setVisibility(View.VISIBLE);
            }else{
                headview_jg.findViewById(R.id.constraintLayout2).setVisibility(View.GONE);
            }
            ((TextView) headview_jg.findViewById(R.id.textView135)).setText("项目状态："+ddxqBean.getData().getStatus().toString());
           // ((TextView)headview_jg.findViewById(R.id.xmxq_headview_ddyy_content)).setText((String)ddxqBean.getData().getReasons());
        }




        else if ((double)ddxqBean.getData().getStatusType() == 8&&genre == 2){
            xmxqMyLl.setVisibility(View.GONE);
            if (ddxqBean.getData().getServiceCoun() !=null){
                headview_jg.findViewById(R.id.constraintLayout2).setVisibility(View.GONE);
            }else{
                headview_jg.findViewById(R.id.constraintLayout2).setVisibility(View.GONE);
            }
            headview_jg.findViewById(R.id.linearLayout).setVisibility(View.VISIBLE);
            ((TextView)headview_jg.findViewById(R.id.xmxq_headview_ddyy_content)).setText((String)ddxqBean.getData().getReasons());

            ((TextView) headview_jg.findViewById(R.id.textView135)).setText("项目状态："+ddxqBean.getData().getStatus().toString());
            initToolbarThree(R.id.xmxq_my_toolber_include, "项目详情", "", new Callback() {
                @Override
                public void doSomeThing() {
                    Toasts.show(XMXQActivity_my.this, "do something", Toast.LENGTH_SHORT);
                    if ((double)ddxqBean.getData().getStatusType() == 1) {
                        Intent intent = new Intent(XMXQActivity_my.this, YJFKActivity.class);
                        intent.putExtra("who", FragmentsFlag.Activity_XMXQ.ordinal());
                        /**
                         * todo id_dd为订单号
                         */
                        intent.putExtra("id_dd", 0);
                        startActivity(intent);
                    } else if ((double)ddxqBean.getData().getStatusType() == 6) {
                        Intent intent = new Intent(XMXQActivity_my.this, XZJGActivity.class);
                        intent.putExtra("id_dd", 0);
                        startActivity(intent);
                    }
                }
            });
        }


        else if((double)ddxqBean.getData().getStatusType() == 2&&genre == 1){
            xmxqMyLl.setVisibility(View.GONE);
            if (ddxqBean.getData().getServiceCoun() !=null){
                headview_jg.findViewById(R.id.constraintLayout2).setVisibility(View.VISIBLE);
            }else{
                headview_jg.findViewById(R.id.constraintLayout2).setVisibility(View.GONE);
            }
            headview_jg.findViewById(R.id.linearLayout).setVisibility(View.VISIBLE);
            ((TextView)headview_jg.findViewById(R.id.xmxq_headview_ddyy)).setText("未通过原因");
            ((TextView)headview_jg.findViewById(R.id.xmxq_headview_ddyy_content)).setText((String)ddxqBean.getData().getReasons());

            ((TextView) headview_jg.findViewById(R.id.textView135)).setText("项目状态："+ddxqBean.getData().getStatus().toString());
            initToolbarThree(R.id.xmxq_my_toolber_include, "项目详情", "", new Callback() {
                @Override
                public void doSomeThing() {
                    Toasts.show(XMXQActivity_my.this, "do something", Toast.LENGTH_SHORT);
                    if ((double)ddxqBean.getData().getStatusType() == 1) {
                        Intent intent = new Intent(XMXQActivity_my.this, YJFKActivity.class);
                        intent.putExtra("who", FragmentsFlag.Activity_XMXQ.ordinal());
                        /**
                         * todo id_dd为订单号
                         */
                        intent.putExtra("id_dd", 0);
                        startActivity(intent);
                    } else if ((double)ddxqBean.getData().getStatusType() == 6) {
                        Intent intent = new Intent(XMXQActivity_my.this, XZJGActivity.class);
                        intent.putExtra("id_dd", 0);
                        startActivity(intent);
                    }
                }
            });
        }
        else if((double)ddxqBean.getData().getStatusType() == 4&&genre == 1){
            xmxqMyLl.setVisibility(View.GONE);
            if (ddxqBean.getData().getServiceCoun() !=null){
                headview_jg.findViewById(R.id.constraintLayout2).setVisibility(View.VISIBLE);
            }else{
                headview_jg.findViewById(R.id.constraintLayout2).setVisibility(View.GONE);
            }
            headview_jg.findViewById(R.id.linearLayout).setVisibility(View.GONE);
            ((TextView)headview_jg.findViewById(R.id.xmxq_headview_ddyy)).setText("拒单原因");
            ((TextView)headview_jg.findViewById(R.id.xmxq_headview_ddyy_content)).setText((String)ddxqBean.getData().getReasons());

            ((TextView) headview_jg.findViewById(R.id.textView135)).setText("项目状态："+ddxqBean.getData().getStatus().toString());
            initToolbarThree(R.id.xmxq_my_toolber_include, "项目详情", "帮我找机构", new Callback() {
                @Override
                public void doSomeThing() {
                    helpFindJG();
                }
            });
        }
        else if((double)ddxqBean.getData().getStatusType() == 9&&genre == 1){
            xmxqMyLl.setVisibility(View.GONE);
            if (ddxqBean.getData().getServiceCoun() !=null){
                headview_jg.findViewById(R.id.constraintLayout2).setVisibility(View.VISIBLE);
            }else{
                headview_jg.findViewById(R.id.constraintLayout2).setVisibility(View.GONE);
            }
            headview_jg.findViewById(R.id.linearLayout).setVisibility(View.GONE);
            ((TextView)headview_jg.findViewById(R.id.xmxq_headview_ddyy)).setText("拒单原因");
            ((TextView)headview_jg.findViewById(R.id.xmxq_headview_ddyy_content)).setText((String)ddxqBean.getData().getReasons());

            ((TextView) headview_jg.findViewById(R.id.textView135)).setText("项目状态："+ddxqBean.getData().getStatus().toString());
            initToolbarThree(R.id.xmxq_my_toolber_include, "项目详情", "", new Callback() {
                @Override
                public void doSomeThing() {
                    Intent intent = new Intent(XMXQActivity_my.this,XZJGActivity.class);
                    intent.putExtra("id_dd",dd_id);
                    startActivity(intent);
                }
            });
        }
        else if((double)ddxqBean.getData().getStatusType() == 8&&genre == 1){
            xmxqMyLl.setVisibility(View.GONE);
            if (ddxqBean.getData().getServiceCoun() !=null){
                headview_jg.findViewById(R.id.constraintLayout2).setVisibility(View.VISIBLE);
            }else{
                headview_jg.findViewById(R.id.constraintLayout2).setVisibility(View.GONE);
            }
            headview_jg.findViewById(R.id.linearLayout).setVisibility(View.VISIBLE);
            ((TextView)headview_jg.findViewById(R.id.xmxq_headview_ddyy)).setText("项目失败原因");
            ((TextView)headview_jg.findViewById(R.id.xmxq_headview_ddyy_content)).setText((String)ddxqBean.getData().getReasons());

            ((TextView) headview_jg.findViewById(R.id.textView135)).setText("项目状态："+ddxqBean.getData().getStatus().toString());
            initToolbarThree(R.id.xmxq_my_toolber_include, "项目详情", "帮我找机构", new Callback() {
                @Override
                public void doSomeThing() {
                    Intent intent = new Intent(XMXQActivity_my.this,XZJGActivity.class);
                    intent.putExtra("id_dd",dd_id);
                    startActivity(intent);
                }
            });
        }

        /**
         * 推送机构中
         */
        else if((double)ddxqBean.getData().getStatusType() == 5&&genre == 1){
            xmxqMyLl.setVisibility(View.GONE);
            if (ddxqBean.getData().getServiceCoun()!=null){
                headview_jg.findViewById(R.id.constraintLayout2).setVisibility(View.VISIBLE);
            }else{
                headview_jg.findViewById(R.id.constraintLayout2).setVisibility(View.GONE);
            }

            headview_jg.findViewById(R.id.linearLayout).setVisibility(View.GONE);
            ((TextView)headview_jg.findViewById(R.id.xmxq_headview_ddyy)).setText("项目失败原因");
            ((TextView)headview_jg.findViewById(R.id.xmxq_headview_ddyy_content)).setText((String)ddxqBean.getData().getReasons());

            ((TextView) headview_jg.findViewById(R.id.textView135)).setText("项目状态："+ddxqBean.getData().getStatus().toString());
            initToolbarThree(R.id.xmxq_my_toolber_include, "项目详情", "", new Callback() {
                @Override
                public void doSomeThing() {
                    Toasts.show(XMXQActivity_my.this, "do something", Toast.LENGTH_SHORT);
                    if ((double)ddxqBean.getData().getStatusType() == 1) {
                        Intent intent = new Intent(XMXQActivity_my.this, YJFKActivity.class);
                        intent.putExtra("who", FragmentsFlag.Activity_XMXQ.ordinal());
                        /**
                         * todo id_dd为订单号
                         */
                        intent.putExtra("id_dd", 0);
                        startActivity(intent);
                    } else if ((double)ddxqBean.getData().getStatusType() == 6) {
                        Intent intent = new Intent(XMXQActivity_my.this, XZJGActivity.class);
                        intent.putExtra("id_dd", 0);
                        startActivity(intent);
                    }
                }
            });
        }

        /**
         * 自己找机构——待选择机构
         */
        else if((double)ddxqBean.getData().getStatusType() == 6&&genre == 1){
            xmxqMyLl.setVisibility(View.GONE);
            if (ddxqBean.getData().getServiceCoun() !=null){
                headview_jg.findViewById(R.id.constraintLayout2).setVisibility(View.VISIBLE);
            }else{
                headview_jg.findViewById(R.id.constraintLayout2).setVisibility(View.GONE);
            }
            headview_jg.findViewById(R.id.linearLayout).setVisibility(View.GONE);
            ((TextView)headview_jg.findViewById(R.id.xmxq_headview_ddyy)).setText("项目失败原因");
            ((TextView)headview_jg.findViewById(R.id.xmxq_headview_ddyy_content)).setText((String)ddxqBean.getData().getReasons());

            ((TextView) headview_jg.findViewById(R.id.textView135)).setText("项目状态："+ddxqBean.getData().getStatus().toString());
            initToolbarThree(R.id.xmxq_my_toolber_include, "项目详情", "选择机构", new Callback() {
                @Override
                public void doSomeThing() {
                    Intent intent = new Intent(XMXQActivity_my.this,XZJGActivity.class);
                    intent.putExtra("id_dd",dd_id);
                    startActivity(intent);
                }
            });
        }

        /**
         * 自己找机构——待选择机构
         */
        else if((double)ddxqBean.getData().getStatusType() == 7&&genre == 1){
            xmxqMyLl.setVisibility(View.GONE);
            if (ddxqBean.getData().getServiceCoun() !=null){
                headview_jg.findViewById(R.id.constraintLayout2).setVisibility(View.VISIBLE);
            }else{
                headview_jg.findViewById(R.id.constraintLayout2).setVisibility(View.GONE);
            }
            headview_jg.findViewById(R.id.linearLayout).setVisibility(View.GONE);
            ((TextView)headview_jg.findViewById(R.id.xmxq_headview_ddyy)).setText("项目失败原因");
            ((TextView)headview_jg.findViewById(R.id.xmxq_headview_ddyy_content)).setText((String)ddxqBean.getData().getReasons());

            ((TextView) headview_jg.findViewById(R.id.textView135)).setText("项目状态："+ddxqBean.getData().getStatus().toString());
            initToolbarThree(R.id.xmxq_my_toolber_include, "项目详情", "", new Callback() {
                @Override
                public void doSomeThing() {
                    Intent intent = new Intent(XMXQActivity_my.this,XZJGActivity.class);
                    intent.putExtra("id_dd",dd_id);
                    startActivity(intent);
                }
            });
        }

        /**
         * 自己找机构——待接单
         */
        else if((double)ddxqBean.getData().getStatusType() == 3&&genre == 1){
            xmxqMyLl.setVisibility(View.GONE);
            if (ddxqBean.getData().getServiceCoun() !=null){
                headview_jg.findViewById(R.id.constraintLayout2).setVisibility(View.VISIBLE);
            }else{
                headview_jg.findViewById(R.id.constraintLayout2).setVisibility(View.GONE);
            }
            headview_jg.findViewById(R.id.linearLayout).setVisibility(View.GONE);
            ((TextView)headview_jg.findViewById(R.id.xmxq_headview_ddyy)).setText("取消订单原因");
            ((TextView)headview_jg.findViewById(R.id.xmxq_headview_ddyy_content)).setText((String)ddxqBean.getData().getReasons());

            ((TextView) headview_jg.findViewById(R.id.textView135)).setText("项目状态："+ddxqBean.getData().getStatus().toString());
            initToolbarThree(R.id.xmxq_my_toolber_include, "项目详情", "取消订单", new Callback() {
                @Override
                public void doSomeThing() {
                    Intent intent = new Intent(XMXQActivity_my.this, YJFKActivity.class);
                    intent.putExtra("who", FragmentsFlag.Activity_XMXQ.ordinal());
                    /**
                     * todo id_dd为订单号
                     */
                    intent.putExtra("id_dd", ddxqBean.getData().getId());
                    startActivity(intent);
                }
            });
        }

        else if (genre == 2){
            xmxqMyLl.setVisibility(View.GONE);
            if (ddxqBean.getData().getServiceCoun() !=null){
                headview_jg.findViewById(R.id.constraintLayout2).setVisibility(View.GONE);
            }else{
                headview_jg.findViewById(R.id.constraintLayout2).setVisibility(View.GONE);
            }
            headview_jg.findViewById(R.id.linearLayout).setVisibility(View.GONE);
            ((TextView)headview_jg.findViewById(R.id.xmxq_headview_ddyy_content)).setText((String)ddxqBean.getData().getReasons());

            ((TextView) headview_jg.findViewById(R.id.textView135)).setText("项目状态："+ddxqBean.getData().getStatus().toString());
            initToolbarThree(R.id.xmxq_my_toolber_include, "项目详情", "", new Callback() {
                @Override
                public void doSomeThing() {
                    Toasts.show(XMXQActivity_my.this, "do something", Toast.LENGTH_SHORT);
                    if ((double)ddxqBean.getData().getStatusType() == 1) {
                        Intent intent = new Intent(XMXQActivity_my.this, YJFKActivity.class);
                        intent.putExtra("who", FragmentsFlag.Activity_XMXQ.ordinal());
                        /**
                         * todo id_dd为订单号
                         */
                        intent.putExtra("id_dd", 0);
                        startActivity(intent);
                    } else if ((double)ddxqBean.getData().getStatusType() == 6) {
                        Intent intent = new Intent(XMXQActivity_my.this, XZJGActivity.class);
                        intent.putExtra("id_dd", 0);
                        startActivity(intent);
                    }
                }
            });
        }


        RecyclerView recyclerView = (RecyclerView) headview_jg.findViewById(R.id.recyclerView2);
        TextView more = (TextView) headview_jg.findViewById(R.id.textView137);
        more.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(XMXQActivity_my.this, FWJGActivity.class);
                startActivity(intent);
            }
        });
        adapter = new BaseAdapter<MyXMBean.DataBean.ABean.ServiceCounBean>(this, ddxqBean.getData().getServiceCoun()) {
            @Override
            public void convert(final int position, BaseViewHolder holder, final MyXMBean.DataBean.ABean.ServiceCounBean dataBean) {

                if (!TextUtils.isEmpty(dataBean.getZhenshi_img())){
                    Glide.with(XMXQActivity_my.this).load(dataBean.getZhenshi_img()).error(R.drawable.mrtx).into(((ImageView)holder.getView(R.id.imageView48)));
                }
                if(dataBean.getIs_eval() == 1){
                    ((TextView)holder.getView(R.id.textView145)).setText("已评价");
                }else{
                    ((TextView)holder.getView(R.id.textView145)).setText("评价机构>>");
                    ((TextView) holder.getView(R.id.textView145)).setOnClickListener(new View.OnClickListener() {
                        @RequiresApi(api = Build.VERSION_CODES.KITKAT)
                        @Override
                        public void onClick(View view) {
                            showPopupwindow(R.layout.view_popupwindow_pj, ScreenExpressionUtils.dip2px(XMXQActivity_my.this,335), ScreenExpressionUtils.dip2px(XMXQActivity_my.this,276), R.layout.xmxq_my_activity, new CallbackPopuwindow() {

                                @Override
                                public void doSomeThing(final View view) {

                                    ((TextView)view.findViewById(R.id.textView158)).setOnClickListener(new View.OnClickListener() {
                                        @Override
                                        public void onClick(View view) {
                                            Toasts.show(XMXQActivity_my.this, "this is ", Toast.LENGTH_SHORT);
                                            popWindow.dissmiss();
                                        }
                                    });

                                    (view.findViewById(R.id.textView159)).setOnClickListener(new View.OnClickListener() {
                                        @Override
                                        public void onClick(View view_) {
                                            int scroe = (int) ((SimpleRatingBar)view.findViewById(R.id.star_scroe)).getRating();
                                            requestPjData(dataBean.getUsers_id(),scroe*2,position);
                                            popWindow.dissmiss();
                                        }
                                    });

                                }
                            });
                        }
                    });
                }

                ((TextView)holder.getView(R.id.textView139)).setText(dataBean.getCompany()+"-"+dataBean.getName());
                ((TextView)holder.getView(R.id.textView140)).setText("机构地址：" + dataBean.getCity());


                //if ((double)ddxqBean.getData().getStatusType() != 9 || (double)ddxqBean.getData().getStatusType() != 4)

                ((TextView)holder.getView(R.id.textView142)).setText(dataBean.getStatus());


                if ((double)ddxqBean.getData().getStatusType() != 9){//评价是否显示
                    ((TextView) holder.getView(R.id.textView145)).setVisibility(View.INVISIBLE);
                }else{
                    ((TextView) holder.getView(R.id.textView145)).setVisibility(View.VISIBLE);
                }

            }

            @Override
            public int getLayoutId(int viewType) {
                return R.layout.xmxq_my_headview_item;
            }
        };
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(adapter);
    }

    /**
     * 评分
     * @param right_users_id
     * @param scroe
     */
    private void requestPjData(int right_users_id, int scroe, final int position_data) {
        HashMap<String,String> map = new HashMap<>();
        map.put("code",HttpUtil.getParam());
        map.put("users_id",SampleApplicationLike.getUserloginInstance().getId()+"");
        map.put("indent_id",dd_id+"");
        map.put("right_users_id",right_users_id+"");
        map.put("score",scroe+"");
        String json = GetJsonDataUtil.simpleMapToJsonStr(map);
        String url = URLAddress.URLBASE + URLAddress.URL_PJ;
        HttpUtil.RequestGsonPost(SampleApplicationLike.getQueueInstance(), Request.Method.POST, ResultBean.class, url, map, new Response.Listener() {
            @Override
            public void onResponse(Object response) {
                ResultBean b = (ResultBean) response;
                if (b.getResult() == 1){
                    ddxqBean.getData().getServiceCoun().get(position_data).setIsPj("已评价");
                    Toasts.show(XMXQActivity_my.this, "评价成功", Toast.LENGTH_SHORT);
                    adapter.notifyDataSetChanged();
                }else{
                    Toasts.show(XMXQActivity_my.this, ""+b.getErr_msg(), Toast.LENGTH_SHORT);
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });
    }

    private void helpFindJG() {
        DialogUtil.showProgressbar(this,R.layout.xmxq_my_activity);
        HashMap<String,String> map = new HashMap<>();
        map.put("code",HttpUtil.getParam());
        map.put("indent_id",dd_id+"");
        String json = GetJsonDataUtil.simpleMapToJsonStr(map);
        String url = URLAddress.URLBASE + URLAddress.URL_FPJG;
        HttpUtil.RequestGsonPost(SampleApplicationLike.getQueueInstance(), Request.Method.POST, ResultBean.class, url, map, new Response.Listener() {
            @Override
            public void onResponse(Object response) {
                ResultBean resultBean = (ResultBean) response;
                if (resultBean.getResult() == 1){
                    DialogUtil.loading.dissmiss();
                    startActivity(new Intent(XMXQActivity_my.this,SuccessActivity.class));

                }else{
                    DialogUtil.loading.dissmiss();
                    Toasts.show(XMXQActivity_my.this, ""+resultBean.getErr_msg(), Toast.LENGTH_SHORT);
                }
                DialogUtil.loading.dissmiss();
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                DialogUtil.loading.dissmiss();
            }
        });
    }


    @OnClick({R.id.xmxq_my_button_jjjd, R.id.xmxq_my_button_ljjd})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.xmxq_my_button_jjjd:
                Intent intent = new Intent(XMXQActivity_my.this, YJFKActivity.class);
                intent.putExtra("who", FragmentsFlag.Activity_XMXQ_JJJD.ordinal());
                intent.putExtra("id_dd",ddxqBean.getData().getId());
//                /**
//                 * todo id_dd为订单号
//                 */
//                intent.putExtra("id_dd", 0);
                startActivity(intent);
                break;
            case R.id.xmxq_my_button_ljjd:
                requestLJJD();
                break;
        }
    }

    private void requestLJJD() {
        HashMap<String,String> map = new HashMap<>();
        map.put("code",HttpUtil.getParam());
        map.put("indent_id",dd_id+"");
        map.put("users_id",SampleApplicationLike.getUserloginInstance().getId()+"");
        HttpUtil.RequestGsonPost(SampleApplicationLike.getQueueInstance(), Request.Method.POST, ResultBean.class, URLAddress.URLBASE + URLAddress.URL_LJJD, map, new Response.Listener() {
            @Override
            public void onResponse(Object response) {
                ResultBean bean = (ResultBean) response;
                if (bean.getResult() == 1){
                    Intent intent = new Intent(XMXQActivity_my.this, SuccessActivity.class);
                    intent.putExtra("who",FragmentsFlag.XMXQActivity.ordinal());
                    startActivity(intent);
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });

    }

    @Override
    protected void onRestart() {
        super.onRestart();
        requestXMXQ();
    }
}
